/*
 * @Author: Liu
 * @Date: 2023-05-08 16:39:44
 * @LastEditTime: 2023-05-16 10:52:41
 */
import vueCookies from 'vue-cookies';
import api from "../axios/index";
import utils from "../utils";

// 登录
export const login = (params) => {
    return api.post("/user/login", params);
    // return new Promise((resolve,reject) => {
    //     setTimeout(() => {
    //         resolve( {
    //             "data": {
    //                 "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmcmVzaCI6ZmFsc2UsImlhdCI6MTY5Nzk2MTE0OCwianRpIjoiMzliYjRhNWEtNzJlMC00OWIyLTk1ZjEtMzRjMmZlMTg2NjQwIiwidHlwZSI6ImFjY2VzcyIsInN1YiI6MSwibmJmIjoxNjk3OTYxMTQ4LCJleHAiOjE2OTg1NjU5NDh9.7WfQbLgsZLHLeD0Tpt1ErCynjG4v2rbIf_KExe_zzz4",
    //                 "qrcode": "https://wework.qpic.cn/wwpic/567378_j1A123rdQIueZVB_1695390320/0"

    //             },
    //             "error_code": '1001',
    //             "msg": "ok",
    //             "request": "POST /chess1026api/user/login"
    //         })
    //     }, 1000);
    // })
}

export const userUserAccess = () => api.post()
// 获取用户信息
export const getUserData=()=>{
    return api.get("/user/info")
}

// 查询游戏排行榜
export const getRankingList = () =>{
    return api.get("/user/rank/list")
}

// 人机验证校验
export const userAuth = (data) => {
    // return api.post("//user/user_auth", data);
    return api({
        url: '/user/user_auth',
        method: 'post',
        data,
        headers: {
            'X-CSRF-TOKEN': vueCookies.get('csrf_access_token'),
            'content-type': 'multipart/form-data'
        }
    })
}

// 游戏开始
export const gameStart = () =>{
    // return api.post("//user/game/start")
    // return  new Promise((resolve) => {
    //     setTimeout(() => {
    //         resolve({
    //             "data": null,
    //             "error_code": 999,
    //             "msg": "很遗憾<br />当前活动已结束",
    //             "request": "GET /chess1026api/user/activity"
    //         })
    //     }, 1000);
    // })
    // return new Promise((resolve) => {
    //     setTimeout(() => {
    //         resolve({
    //             "data": {
    //                 "id": 98
    //             },
    //             "error_code": 0,
    //             "msg": "ok",
    //             "request": "POST /chess1026api/user/game/start"
    //         })
    //     }, 1000);
    // })
    return api({
        url: '/user/game/start',
        method: 'post',
        headers: {
            'X-CSRF-TOKEN': vueCookies.get('csrf_access_token')
        }
    })
}

// 游戏结束
export const gameEnd = (params) => {
    // return api.post("//user/game/end")
    // return new Promise((resolve) => {
    //     setTimeout(() => {
    //         resolve( {
    //             "data": {
    //                 "category": 6,
    //                 "content": null,
    //                 "dice_num": 10,
    //                 "get_remain_game_num": 495,
    //                 "icon": "https://yinli-qixi-run.varwey.com/2023_ca/u_chess/touzi.jpg",
    //                 "id": 1,
    //                 "name": "再投一次",
    //                 "rank_exchange_dict": {
                        
    //                 },
    //                 "total_dice_num": 50,
    //                 "u_num": 0
    //             },
    //             "error_code": 0,
    //             "msg": "ok",
    //             "request": "POST /chess1026api/user/game/end"
    //         })
    //     }, 1000);
    // })
    return api({
        url: '/user/game/end',
        method: 'post',
        data: params,
        headers: {
            'X-CSRF-TOKEN': vueCookies.get('csrf_access_token'),
            'content-type': 'multipart/form-data'
        }
    })
}
// 检测是否游戏时间内
export const userActivity= () => {
    // return new Promise((resolve) => {
    //     setTimeout(() => {
    //         resolve({
    //             "data": null,
    //             "error_code": 999,
    //             "msg": "很遗憾<br />当前活动已结束",
    //             "request": "GET /chess1026api/user/activity"
    //         })
    //     }, 1000);
    // })
    return api.get('/user/activity')
}
// 查询剩余次数
export const gameTimes = () =>{
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve({
                "data": {
                    "remain_game_num": 1000
                },
                "error_code": 0,
                "msg": "ok",
                "request": "GET /chess1026api/user/game/num"
            })
        }, 1000);
    })
    return api.get("/user/game/num")
}

//抽奖

export const lottery = () =>{
    return api.post("/java-api/for520/lottery?activityId=520")
}

// 我的奖品
export const getGifts = (data) =>{
    return api.get("/user/gifts",{
        params:data
    })
}
// 保存用户手机号码，地址
export const userInfoModify = (data) => {
    return api.post("/user/info/modify",data)
}
// 设置车型
export const userCarType = (data) => {
    return api.post('/user/car_type',data)
}
// 奖品信息
export const weekGift = (data) =>{
    return api.get("/user/week/gift")
}

// 奖品信息
export const getScore = (data) =>{
    return api.get("/user/score")
}

// 分享
export const shareRecord = (data) =>{
    return api.get("/user/share")
}


// 中奖海报加字上传
export const submitUserPoster = (params,id) =>{   
    // console.log(api.options)
    return api({
        url: '/java-api/for520/upload/submitUserPoster?id='+ id,
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded '
         }, 
        data: params
      })
    // return api.post("/java-api/for520/submitUserPoster",{...params})
}

// 查询用户的中奖海报
export const getPosterUrl = (data) =>{
    return api.get("/java-api/for520/getPosterUrl",{
        params:data
        
    })
}

// 转发获得抽奖机会

export const share = (params) =>{
    return api.post("/java-api/for520/share?activityId=520")
}


export const userQrcode = () => api.get('/user/qrcode')
export const _wx_config = async (data) => {
    return api.post('/user/wechat_share_info',data)
    const resp = await requewt(`${API.wx.config}`, {
      method: `POST`,
      headers: {
        "Content-Type": "multipart/form-data"
      },
      body: {
        url
      }
    });
    if (resp?.error_code !== 0 || resp?.msg !== `ok`) return;
  
    return resp.data;
  }